local wdtx__snatchSkill = fk.CreateSkill {
  name = "wdtx__snatch_skill",
}


wdtx__snatchSkill:addEffect("cardskill", {
  name = "wdtx__snatch_skill",
  prompt = "#wdtx__snatch_skill",
  distance_limit = 1,
  mod_target_filter = function(self, to_select, selected, user, card, distance_limited)
    local player = to_select
    local from = user
    return from ~= player and not (player:isAllNude() or (distance_limited and not self:withinDistanceLimit(from, false, card, player)))
  end,
  target_filter = function(self, player, to_select, selected, _, card, extra_data)
    local count_distances = not (extra_data and extra_data.bypass_distances)
    if card:getMark("@up_snatch") > 0 then
      count_distances = false
    end
    if #selected < self:getMaxTargetNum(player, card) then
      return self:modTargetFilter(to_select, selected, player, card, count_distances)
    end
  end,
  target_num = 1,
  on_effect = function(self, room, effect)
    local from = effect.from
    local to = effect.to
    if from.dead or to.dead or to:isAllNude() then return end
    local cid
    if room.logic.class.name == "wdtx_logic" and effect.card:getMark("@up_snatch") > 0 then 
      local extra_add = effect.card:getMark("@up_snatch") + 1
      cid = room:askToChooseCards(from,{
        max = math.min(extra_add,#to:getCardIds("hej")),
        min = 1,
        flag = "hej",
        skill_name = wdtx__snatchSkill.name,
        target = to,
      })
    else
      cid = room:askToChooseCard(from,{
        flag = "hej",
        skill_name = wdtx__snatchSkill.name,
        target = to,
      })
    end
    room:obtainCard(from, cid, false, fk.ReasonPrey)
  end
})

return wdtx__snatchSkill